package syswk.com.tanksgame;

import java.awt.*;
import java.util.Vector;

/**
 * 作者：swk
 * 时间：
 * 公司：
 **/
@SuppressWarnings({"all"})
public class EnemyTank extends Tank implements Runnable {
    Vector<Shot> shots = new Vector<>();

    public EnemyTank(int x, int y, int direct, Boolean lift, Color color) {
        super(x, y, direct, lift, color);
    }

    @Override
    public void run() {
        while (this.getLift()) {
            Shot shot = null;
            switch (getDirect()) {
                case 0:
                    if (shots.size() <= 0) {
                        shot = new Shot(getX() + 20, getY(), 0, true, 2);
                        shots.add(shot);
                        new Thread(shot).start();
                    }
                    for (int i = 0; i < tankGames.MOVE_STEPS_NUM; i++) {
                        if (getY() > 0) {
                            moveUp();
                        }
                        try {
                            Thread.sleep(50);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    break;
                case 1:
                    if (shots.size() <= 0) {
                        shot = new Shot(getX() + 60, getY() + 20, 1, true, 2);
                        shots.add(shot);
                        new Thread(shot).start();
                    }
                    for (int i = 0; i < tankGames.MOVE_STEPS_NUM; i++) {
                        if (getX() + 80 < tankGames.WIDTH) {
                            moveRight();
                        }
                        try {
                            Thread.sleep(50);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }

                    break;
                case 2:
                    if (shots.size() <= 0) {
                        shot = new Shot(getX() + 20, getY() + 60, 2, true, 2);
                        shots.add(shot);
                        new Thread(shot).start();
                    }
                    for (int i = 0; i < tankGames.MOVE_STEPS_NUM; i++) {
                        if (getY() + 100 < tankGames.HEIGHT) {
                            moveDown();
                        }
                        try {
                            Thread.sleep(50);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }

                    break;
                case 3:
                    if (shots.size() <= 0) {
                        shot = new Shot(getX(), getY() + 20, 3, true, 2);
                        shots.add(shot);
                        new Thread(shot).start();
                    }
                    for (int i = 0; i < tankGames.MOVE_STEPS_NUM; i++) {
                        if (getX() > 0) {
                            moveLeft();
                        }
                        try {
                            Thread.sleep(50);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }

                    break;
            }
            setDirect((int) (Math.random() * 4));
        }
    }
}
